/*
 *  linux/arch/arm/mach-a2f/include/mach/fpga.h
 *  Header for the SmartFusion FPGA managent code. Includes:
 * - Generic set-up to allow DMA-style accessed to MSS memory by FPGA IP
 * - Demultiplexer for IRQs triggered by FPGA CoreInterrupt
 *
 *  Copyright (C) 2011 Dmitry Cherukhin, Emcraft Systems
 *  Copyright (C) 2012 Vladimir Khusainov, Emcraft Systems
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _MACH_A2F_FPGA_H_
#define _MACH_A2F_FPGA_H_

/*
 * Set up the MSS / FPGA interfaces to allow DMA-style accesses
 * to the MSS memory by an FPGA-based IP
 * @returns		0 (success) or -1 (failure)
 */
extern int a2f_fpga_dma_init(void);

#if defined(CONFIG_A2F_FPGA_CINT)

/*
 * IRQ generated by CoreInterrupt
 */
#define A2F_FPGA_CINT_IRQ		31

#if defined(CONFIG_A2F_FPGA_DEMUX)

/*
 * Software IRQ generated by the demultiplexer
 * if CoreInterrupt IRQ source 0 is triggered;
 * this is the IRQ base for any source within CoreInterrupt
 */
#define A2F_FPGA_DEMUX_IRQ_BASE		(NR_IRQS - 32)

/*
 * If the demultiplexer is used then each CoreInterrupt IRQ source (0..31)
 * is mapped to its own sotfware-generated IRQ.
 */
#define A2F_FPGA_DEMUX_IRQ_MAP(n)	(A2F_FPGA_DEMUX_IRQ_BASE + (n))

/*
 * Initialize the demultiplexer for IRQ generated by FPGA CoreInterrupt
 */
extern void a2f_fpga_demux_init(void);

#else /* !CONFIG_A2F_FPGA_DEMUX */

/*
 * If the demultiplexer is not used then any CoreInterrupt IRQ source
 * is mapped to IRQ generated by CoreInterrupt
 */
#define A2F_FPGA_DEMUX_IRQ_MAP(n)	A2F_FPGA_CINT_IRQ

#endif /* CONFIG_A2F_FPGA_DEMUX */

/*
 * Attach IRQ source to the demultiplexer; this function should be
 * called for each IRQ source within CoreInterrupt during init time.
 * If the demultiplexer is not used, then this function enables
 * IRQ source within CoreInterrupt.
 * @param irq		IRQ source within CoreInterrupt (0..31)
 * @returns		0 -> success, < 0 -> error code
 */
extern int a2f_fpga_demux_irq_source_enable(unsigned int irq);

#endif /* CONFIG_A2F_FPGA_CINT */

#endif /* _MACH_A2F_FPGA_H_ */

